package com.mall.controller;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.entity.Category;
import com.mall.pojo.ResponseMessage;
import com.mall.service.ICategoryService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ShouPeng
 * @since 2024-01-14
 */
@RestController
@CrossOrigin
public class CategoryController {
    final
    ICategoryService categoryService;

    public CategoryController(ICategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @GetMapping("/category")
    public ResponseMessage queryCategory(@RequestParam(required = false) String parentId){
        if (ObjectUtils.isEmpty(parentId)){
            return ResponseMessage.success(categoryService.queryCategories(new Page<Category>(1,10)));
        }else {
            return ResponseMessage.success(categoryService.queryCategories(new Page<Category>(1,100),parentId));
        }
    }

}

